/**
*
* Titre : StringToISODateConverter.java
* Description :
* Copyright : Copyright (c) 2013 JN Mauclair
* @author : JN MAUCLAIR
* @version : $Revision: $
*
* $Author$
* $Date$
*
*/
package fr.mauclair.domogeek.persist;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

public class StringToISODateConverter implements Converter<String[], Date> {

	@Override
	public Date convert(String[] s) {
		if (s.length == 1) {
			try {
				return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(s[0]);
			} catch (ParseException e) {
				throw new IllegalArgumentException(e);
			}
		}

		throw new IllegalArgumentException("Can only parse a single date in the parameter.");
	}
}
